<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: pl125 <xskjs888@163.com>
// +----------------------------------------------------------------------

namespace api\v1\controller;

use api\v1\model\Advertise;
use api\v1\model\Article;
use api\v1\model\Category;
use cmf\controller\RestUserBaseController;

/**
 * 首页接口
 * Class IndexController
 * @package api\v1\controller
 */
class IndexController extends RestUserBaseController
{

    public function index() {
        $data = [];
        $banners = Advertise::where('slide_id',1)->where('status',1)->order('list_order desc')->select();
        $ad = Advertise::where('slide_id',2)->where('status',1)->find();
        $data['banners'] = $banners;
        $data['ad'] = $ad;
        $data['notices'] = Article::field("id,title")
            ->where("is_rec",1)
            ->where("status",1)
            ->select();
        $data['categorys'] = Category::with(["products"=>function($query){
            $query->where("issy",1)
                ->withField(['category_id','title','xmgm','xmjd','qtje','jyrsy','shijian','pic'])
                ->where("status",1)
                ->order("sort",'desc')
                //->withLimit(10)
                ->select();
        }])
            ->where("type",1)->order("sort desc")->select();
        $this->success("ok",$data);
    }
    public function article() {
        $this->success("ok",Article::find($this->request->param('id')));
    }

}
